package com.ludaxu.google.tools;

import java.io.File;

import android.os.Environment;

public class FileUtils {
	public static final String CACHE = "cache";
	public static final String ICON = "icon";
	public static final String ROOT = "GooglePlay1";

	/**
	 * 获取图片缓存的文件夹
	 * 
	 * @return
	 */
	public static File getIconDir() {
		return getDir(ICON);
	}

	public static File getDir(String str) {
		StringBuilder path = new StringBuilder();
		if (isSDAvailable()) {

			path.append(Environment.getExternalStorageDirectory()
					.getAbsolutePath());
			path.append(File.separator);// 添加了一个斜线"/"
			path.append(ROOT);
			path.append(File.separator);
			path.append(str);
		} else {
			File cacheDir = UiUtils.getContext().getCacheDir();
			path.append(cacheDir.getAbsolutePath());// /data/data/包名/cache
			path.append(File.separator);
			path.append(str);
		}
		File file = new File(path.toString());
		if (!file.exists() || !file.isDirectory()) {
			file.mkdirs();// 创建文件夹
		}
		return file;

	}

	private static boolean isSDAvailable() {
		// sd卡可用
		if (Environment.getExternalStorageState().equals(
				Environment.MEDIA_MOUNTED)) {
			return true;
		} else {
			return false;
		}
	}

	public static File getCacheDir() {
		System.out.println("路径创建成功");
		return getDir(CACHE);
	}

}
